/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package agents;

import com.springrts.ai.AIFloat3;
import com.springrts.ai.oo.Map;
import com.springrts.ai.oo.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * This class encapsulates useful map information
 * @author xavi
 */
public class MapInfo {
    private Map map;
    private int nMines;
    private float gravity, tidalStrength, maxWind, maxMetal, MetalextractorRadius;
    List<AIFloat3> metalMines;

    public MapInfo(Map map, Resource metal) {
        this.map = map;
        gravity = map.getGravity();
        tidalStrength = map.getTidalStrength();
        maxWind = map.getMaxWind();
        maxMetal = map.getMaxResource(metal);
        MetalextractorRadius = map.getExtractorRadius(metal);
        metalMines = map.getResourceMapSpotsPositions(metal);
        nMines = metalMines.size();
    }

    public float getMetalextractorRadius() {
        return MetalextractorRadius;
    }

    public float getGravity() {
        return gravity;
    }

    public Map getMap() {
        return map;
    }

    public float getMaxMetal() {
        return maxMetal;
    }

    public float getMaxWind() {
        return maxWind;
    }

    public float getTidalStrength() {
        return tidalStrength;
    }
    
    /**
     * Gets the elevation of the map at position (x, z)
     * @param x
     * @param z
     * @return y
     */
    public float getElevationAt(float x, float z){
        return map.getElevationAt(x, z);
    }

    /**
     * Returns iesim position indicating where to place resource extractors on
     * the map.
     * </p>
     * Only the x and z values give from the map, z component is calculated using
     * <code>map.getElevation<c/ode> method. Because the original y was the
     * amount of resource an extractor placed there can make. Now, this
     * information is given by <code>getMetalMapSpotsAmout</code> method.
     */
    public AIFloat3 getMetalMapSpotsPosition(int i){
        float x = metalMines.get(i).x;
        float z = metalMines.get(i).z;
        return new AIFloat3(x, getElevationAt(x, z), z);
    }

    /**
     * This value represents the actual amount of resource an extractor make if
     * is placed in position returned by <code>getMetalMapSpotsPosition</code>
     * with the same index i.
     * </p>
     * You should only compare the y values to each other,
     * and not try to estimate effective output from spots.
     */
    public float getMetalMapSpotsAmout(int i){
        return metalMines.get(i).y;
    }

    public int getNmines() {
        return nMines;
    }
}
